#define  _CRT_SECURE_NO_WARNINGS 1  
#include"Stack.h"

void StackInit(Stack* s)
{
	assert(s);
	s->arr = NULL;
	s->capacity = 0;
	s->top = 0;
}
void StackDestroy(Stack* s)
{
	assert(s);
	free(s->arr);
	s->arr = NULL;
	s->top = 0;
	s->capacity = 0;
}
void StackPush(Stack* s)
{
	assert(s);
	if (s->top == s->capacity)
	{
		int newcapacity = s->capacity == 0 ? 4 : s->capacity * 2;
		DataType* tmp = (DataType*)realloc(s->arr, sizeof(DataType) * newcapacity);
		if (tmp == NULL)
		{
			printf("realloc is fail\n");
			exit(-1);
		}

		s->arr = tmp;
		s->capacity = newcapacity;
	}
}
void StackPop(Stack* s)
{
	assert(s);
	assert(!StackEmpty(s));
	s->top--;
}
DataType StackTop(Stack* s)
{
	assert(s);
	assert(!StackEmpty(s));

	return s->arr[s->top-1];
}
bool StackEmpty(Stack* s)
{
	assert(s);
	return s->top == 0;
}
int StackSiize(Stack* s)
{
	assert(s);
	return s->top;
}